package com.xjrsoft.module.customerTwo.EMP.t_electric_meter_sum.service.impl;
import com.xjrsoft.module.customerTwo.EMP.t_electric_meter_sum.entity.TElectricMeterSum;
import com.xjrsoft.core.tool.utils.CollectionUtil;
import java.util.List;
import com.xjrsoft.module.customerTwo.EMP.t_electric_meter_sum.mapper.TElectricMeterSumMapper;
import com.xjrsoft.module.customerTwo.EMP.t_electric_meter_sum.service.ITElectricMeterSumService;
import com.xjrsoft.core.mp.base.BaseService;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Service;

/**
 *  服务实现类
 *
 * @author dongxinhang
 * @since 2023-07-24
 */
@Service
@AllArgsConstructor
public class TElectricMeterSumServiceImpl extends BaseService<TElectricMeterSumMapper, TElectricMeterSum> implements ITElectricMeterSumService {

	/**
	 * 电量数据汇总
	 * 将电表获取的原始数据，根据日期、房间号汇总，记录每个房间每天耗电量 存入表 t_electric_meter_sum
	 * @param start 开始日期 yyyy-MM-dd
	 * @param end	结束日期 yyyy-MM-dd
	 * @return
	 */
	@Override
	public boolean dealData(String start, String end) {
		//删除原有数据
		this.getBaseMapper().deleteElectricSumData(start,end);
		this.getBaseMapper().deleteElectricityCostRecordsMonth(start.substring(0,4),start.substring(5,7));
		//将数据写入中转表 t_electric_meter_transition 表号每天最小电量
//		this.getBaseMapper().insertTransition(start.replace("-","")+"000000",end.replace("-","")+"000000");
		//汇总中转表数据 表号今天最小电量-昨天最小电量=该表号昨天整天耗电量
		this.getBaseMapper().insertElectricMeterSum(start,end);
		return true;
	}
}